<?php
namespace app\controller;

use app\BaseController;

class Mqtt extends BaseController
{

    // 弹出充电宝-mqtt服务
    public function publish(): void
    {
        try {
            $settings = (new \PhpMqtt\Client\ConnectionSettings)->setUsername('php_service')->setPassword('Developerphp@123');
            $mqtt = new \PhpMqtt\Client\MqttClient('47.102.117.21', 1883, 'test-publish');
            $mqtt->connect($settings, true);
            $mqtt->publish('/RYB/RYB10000000B/user/get', '{FB,1715,86691,1,a315}', 0);
            $mqtt->disconnect();
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }

}